package pl.skubicha.domain;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;

import static javax.persistence.GenerationType.IDENTITY;

import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

/**
 * Users generated by hbm2java
 */
@Entity
@Table( name = "users", catalog = "dziennik" )
public class Users implements java.io.Serializable {

	private static final long serialVersionUID = -4357484129454512356L;

	private Integer id;
	private Groups groups;
	private Roles roles;
	private String login;
	private String password;
	private String firstName;
	private String lastName;
	private String email;
	private boolean status;
	private Integer albumNumber;
	private Set< FinalGrades > finalGrades = new HashSet< FinalGrades >( 0 );
	private Set< Subjects > subjects = new HashSet< Subjects >( 0 );
	private Set< PartialGrades > partialGrades = new HashSet< PartialGrades >( 0 );

	public Users() {
	}

	public Users( final Roles roles, final String login, final String password, final String firstName, final String lastName, final String email, final boolean status ) {
		this.roles = roles;
		this.login = login;
		this.password = password;
		this.firstName = firstName;
		this.lastName = lastName;
		this.email = email;
		this.status = status;
	}

	public Users( final Groups groups, final Roles roles, final String login, final String password, final String firstName, final String lastName, final String email, final boolean status, final Integer albumNumber, final Set< FinalGrades > finalGrades,
			final Set< Subjects > subjects, final Set< PartialGrades > partialGrades ) {
		this.groups = groups;
		this.roles = roles;
		this.login = login;
		this.password = password;
		this.firstName = firstName;
		this.lastName = lastName;
		this.email = email;
		this.status = status;
		this.albumNumber = albumNumber;
		this.finalGrades = finalGrades;
		this.subjects = subjects;
		this.partialGrades = partialGrades;
	}

	@Id
	@GeneratedValue( strategy = IDENTITY )
	@Column( name = "id_user", unique = true, nullable = false )
	public Integer getId() {
		return this.id;
	}

	public void setId( final Integer id ) {
		this.id = id;
	}

	@ManyToOne( fetch = FetchType.LAZY )
	@JoinColumn( name = "id_group" )
	public Groups getGroups() {
		return this.groups;
	}

	public void setGroups( final Groups groups ) {
		this.groups = groups;
	}

	@ManyToOne( fetch = FetchType.LAZY )
	@JoinColumn( name = "id_role", nullable = false )
	public Roles getRoles() {
		return this.roles;
	}

	public void setRoles( final Roles roles ) {
		this.roles = roles;
	}

	@Column( name = "login", nullable = false, length = 25 )
	public String getLogin() {
		return this.login;
	}

	public void setLogin( final String login ) {
		this.login = login;
	}

	@Column( name = "password", nullable = false )
	public String getPassword() {
		return this.password;
	}

	public void setPassword( final String password ) {
		this.password = password;
	}

	@Column( name = "first_name", nullable = false, length = 30 )
	public String getFirstName() {
		return this.firstName;
	}

	public void setFirstName( final String firstName ) {
		this.firstName = firstName;
	}

	@Column( name = "last_name", nullable = false, length = 30 )
	public String getLastName() {
		return this.lastName;
	}

	public void setLastName( final String lastName ) {
		this.lastName = lastName;
	}

	@Column( name = "email", nullable = false, length = 30 )
	public String getEmail() {
		return this.email;
	}

	public void setEmail( final String email ) {
		this.email = email;
	}

	@Column( name = "status", nullable = false )
	public boolean isStatus() {
		return this.status;
	}

	public void setStatus( final boolean status ) {
		this.status = status;
	}

	@Column( name = "album_number", precision = 8, scale = 0 )
	public Integer getAlbumNumber() {
		return this.albumNumber;
	}

	public void setAlbumNumber( final Integer albumNumber ) {
		this.albumNumber = albumNumber;
	}

	@OneToMany( fetch = FetchType.LAZY, mappedBy = "users" )
	public Set< FinalGrades > getFinalGrades() {
		return this.finalGrades;
	}

	public void setFinalGrades( final Set< FinalGrades > finalGrades ) {
		this.finalGrades = finalGrades;
	}

	@OneToMany( fetch = FetchType.EAGER, mappedBy = "users" )
	public Set< Subjects > getSubjects() {
		return this.subjects;
	}

	public void setSubjects( final Set< Subjects > subjects ) {
		this.subjects = subjects;
	}

	@OneToMany( fetch = FetchType.LAZY, mappedBy = "users" )
	public Set< PartialGrades > getPartialGrades() {
		return this.partialGrades;
	}

	public void setPartialGrades( final Set< PartialGrades > partialGrades ) {
		this.partialGrades = partialGrades;
	}

	@Transient
	public String getFullName() {
		return this.firstName + " " + this.lastName;
	}

	public void update( final String login, final String firstName, final String lastName, final String email, final boolean status, final Integer albumNumber, final Groups groups, final Set< PartialGrades > partialGrades ) {
		this.login = login;
		this.firstName = firstName;
		this.lastName = lastName;
		this.email = email;
		this.status = status;
		this.albumNumber = albumNumber;
		this.groups = groups;
		this.partialGrades = partialGrades;
	}

	public void updateGrade( final FinalGrades finalGrades ) {
		this.finalGrades.add( finalGrades );
	}
	
	public void updateGrade( final PartialGrades partialGrades ) {
		this.partialGrades.add( partialGrades );
	}

}
